|
Groovy JDK |
Method Summary | |
---|---|
boolean
|
asBoolean()
Coerce an Object array to a boolean value. |
Object
|
asType(Class clazz)
Converts the given array to either a List, Set, or SortedSet. |
Map
|
collectEntries(Map result, Closure closure)
Iterates through this array transforming each item using the closure as a transformer into a map entry, returning a map of the transformed entries. |
Map
|
collectEntries(Closure closure)
Iterates through this array transforming each item using the closure as a transformer into a map entry, returning a map of the transformed entries. |
Number
|
count(Object value)
Counts the number of occurrences of the given value inside this array. |
Number
|
count(Closure closure)
Counts the number of occurrences which satisfy the given closure from inside this array. |
Map
|
countBy(Closure closure)
Sorts all array members into groups determined by the supplied mapping closure and counts the group size. |
boolean
|
equals(List right)
Determines if the contents of this array are equal to the contents of the given list, in the same order. |
Object
|
first()
Returns the first item from the Object array. |
Collection
|
flatten()
Flatten an array. |
List
|
getAt(Collection indices)
Select a List of items from an Object array using a Collection to identify the indices to be selected. |
List
|
getAt(Range range)
Support the range subscript operator for an Array |
List
|
getAt(IntRange range)
|
List
|
getAt(EmptyRange range)
|
List
|
getAt(ObjectRange range)
|
Object
|
head()
Returns the first item from the Object array. |
Object
|
inject(Object initialValue, Closure closure)
Iterates through the given array, passing in the initial value to the closure along with the first item. |
Iterator
|
iterator()
Attempts to create an Iterator for the given object by first converting it to a Collection. |
String
|
join(String separator)
Concatenates the toString() representation of each
items in this array, with the given String as a separator between each
item.
|
Object
|
last()
Returns the last item from the Object array. |
Object
|
max()
Adds max() method to Object arrays. |
Object
|
max(Closure closure)
Selects the maximum value found from the Object array using the closure to determine the correct ordering. |
Object
|
max(Comparator comparator)
Selects the maximum value found from the Object array using the given comparator. |
Object
|
min()
Adds min() method to Object arrays. |
Object
|
min(Comparator comparator)
Selects the minimum value found from the Object array using the given comparator. |
Object
|
min(Closure closure)
Selects the minimum value found from the Object array using the closure to determine the correct ordering. |
Object[]
|
minus(Collection removeMe)
Create an array composed of the elements of the first array minus the elements of the given collection. |
Object[]
|
minus(Object[] removeMe)
Create an array composed of the elements of the first array minus the elements of the given array. |
Object[]
|
minus(Object operand)
Create a new object array composed of the elements of the first array minus the operand. |
Object[]
|
reverse()
Reverse the items in an Object array. |
Object[]
|
reverseEach(Closure closure)
Iterate over each element of the array in the reverse order. |
int
|
size()
Provide the standard Groovy size() method for an array.
|
Object[]
|
sort()
Modifies this array so that its elements are in sorted order. |
Object[]
|
sort(Comparator comparator)
Sorts the given array into sorted order using the given comparator. |
Object[]
|
sort(Closure closure)
Sorts the given Object array into a newly created array using the Closure to determine the correct ordering. |
Object
|
sum()
Sums the items in an array. |
Object
|
sum(Object initialValue)
Sums the items in an array, adding the result to some initial value. |
Object
|
sum(Closure closure)
Sums the result of apply a closure to each item of an array. |
Object
|
sum(Object initialValue, Closure closure)
Sums the result of applying a closure to each item of an array to some initial value. |
Object[]
|
tail()
Returns the items from the Object array excluding the first item. |
String
|
toArrayString()
Returns the string representation of the given array. |
List
|
toList()
Allows conversion of arrays into a mutable List. |
SpreadMap
|
toSpreadMap()
Creates a spreadable map from this array. |
String
|
toString()
Returns the string representation of this array's contents. |
Method Detail |
---|
public boolean asBoolean()
public Object asType(Class clazz)
clazz
- the desired class.public Map collectEntries(Map result, Closure closure)
def letters = "abc" def nums = [0, 1, 2] as Integer[] // collect letters with index assert nums.collectEntries( [:] ) { index -> [index, letters[index]] } == [0:'a', 1:'b', 2:'c'] assert nums.collectEntries( [4:'d'] ) { index -> [(index+1): letters[index]] } == [1:'a', 2:'b', 3:'c', 4:'d']
result
- the Map into which the collected entries are put.closure
- the closure used for mapping, which has an item from self as the parameter and
should return a Map.Entry, a Map or a two-element list containing the resulting key and value.public Map collectEntries(Closure closure)
def letters = "abc" def nums = [0, 1, 2] as Integer[] // collect letters with index using list style assert nums.collectEntries { index -> [index, letters[index]] } == [0:'a', 1:'b', 2:'c'] // collect letters with index using map style assert nums.collectEntries { index -> [(index): letters[index]] } == [0:'a', 1:'b', 2:'c']
closure
- the closure used for mapping, which has an item from self as the parameter and
should return a Map.Entry, a Map or a two-element list containing the resulting key and value.public Number count(Object value)
compareTo(value) == 0
or equals(value)
).value
- the value being searched for.public Number count(Closure closure)
closure
- a closure condition.public Map countBy(Closure closure)
Example usage:
assert ([1,2,2,2,3] as Object[]).countBy{ it % 2 } == [1:2, 0:3]
closure
- a closure mapping items to the frequency keys.public boolean equals(List right)
false
if either collection is null
.right
- the list being compared.public Object first()
def array = [3, 4, 2].toArray() assert array.first() == 3
public Collection flatten()
public List getAt(Collection indices)
indices
- a Collection of indices.public List getAt(Range range)
range
- a Range.public List getAt(IntRange range)
range
- an IntRange.public List getAt(EmptyRange range)
range
- an EmptyRange.public List getAt(ObjectRange range)
range
- an ObjectRange.public Object head()
def array = [3, 4, 2].toArray() assert array.head() == 3
public Object inject(Object initialValue, Closure closure)
initialValue
- some initial value.closure
- a closure.public Iterator iterator()
public String join(String separator)
toString()
representation of each
items in this array, with the given String as a separator between each
item.separator
- a String separator.public Object last()
def array = [3, 4, 2].toArray() assert array.last() == 2
public Object max()
public Object max(Closure closure)
closure
- a Closure used to determine the correct ordering.public Object max(Comparator comparator)
comparator
- a Comparator.public Object min()
public Object min(Comparator comparator)
comparator
- a Comparator.public Object min(Closure closure)
closure
- a Closure used to determine the correct ordering.public Object[] minus(Collection removeMe)
removeMe
- a Collection of elements to remove.public Object[] minus(Object[] removeMe)
removeMe
- an array of elements to remove.public Object[] minus(Object operand)
operand
- an element to remove from the array.public Object[] reverse()
public Object[] reverseEach(Closure closure)
closure
- a closure to which each item is passed.public int size()
size()
method for an array.public Object[] sort()
public Object[] sort(Comparator comparator)
comparator
- a Comparator used for the comparison.public Object[] sort(Closure closure)
closure
- a Closure used to determine the correct ordering.public Object sum()
public Object sum(Object initialValue)
initialValue
- the items in the array will be summed to this initial value.public Object sum(Closure closure)
array.sum(closure)
is equivalent to:
array.collect(closure).sum()
.closure
- a single parameter closure that returns a numeric value..public Object sum(Object initialValue, Closure closure)
array.sum(initVal, closure)
is equivalent to:
array.collect(closure).sum(initVal)
.closure
- a single parameter closure that returns a numeric value..initialValue
- the closure results will be summed to this initial value.public Object[] tail()
String[] strings = ["a", "b", "c"] def result = strings.tail() assert strings.class.componentType == String
public String toArrayString()
{1, 2, "a"}
.public List toList()
public SpreadMap toSpreadMap()
public String toString()
|
Groovy JDK |